package com.fausto.learnimprint.domain

import cn.hutool.core.date.DateTime
import com.baomidou.mybatisplus.core.conditions.update.UpdateWrapper
import com.baomidou.mybatisplus.extension.plugins.pagination.Page
import com.fausto.learnimprint.BlogApplicationTests
import com.fausto.learnimprint.core.service.impl.AnnouncementServiceImpl
import org.junit.jupiter.api.Assertions
import org.junit.jupiter.api.Test
import org.springframework.beans.factory.annotation.Autowired

class AnnouncementTests : BlogApplicationTests() {
    @Autowired
    lateinit var announcementServiceImpl: AnnouncementServiceImpl

    /**
     *      测试新增公告
     */
    @Test
    fun testSave() {

        Assertions.assertEquals(
            true,
            announcementServiceImpl.save(com.fausto.learnimprint.core.model.entity.Announcement().apply {
                announcementTitle = "测试新增公告"
                announcementBody = "测试内容"
                announcementTime = DateTime.now().toLocalDateTime()
            })
        )
    }

    /**
     *      测试删除公告
     */
    @Test
    fun testRemove() {
        Assertions.assertEquals(
            true,
            announcementServiceImpl.removeById(12)
        )
    }

    /**
     *      测试更新公告置顶状态
     */
    @Test
    fun testUpdate() {
        Assertions.assertEquals(
            true,
            announcementServiceImpl.update(UpdateWrapper<com.fausto.learnimprint.core.model.entity.Announcement?>().apply {
                eq("announcement_id", 13)
                set("announcement_top", 0)
            })
        )
    }

    /**
     *      测试查询公告
     */
    @Test
    fun testQueryPage() {
        announcementServiceImpl.page(
            Page(1, 5)
        ).records.forEach(::println)
    }

    @Test
    fun queryCache() {
        announcementServiceImpl.getCacheAnnouncement(1, 5).forEach(::println)
    }
}